package com.ss.lambda.demo3;

import java.util.function.Predicate;

/**
 * @Auther: ljy.s
 * @Date: 2022/9/12 - 09 - 12 - 16:07
 */
public class PredicateLambda {
    // 这是一个main方法，是程序的入口：
    public static void main(String[] args) {
        andMethod(s -> s.contains("W"), s -> s.contains("H"));
        orMethod(s -> s.contains("w"), s -> s.contains("H"));
        negateMethod(s -> s.length() < 5);
    }

    static void andMethod(Predicate<String> one, Predicate<String> two) {
        boolean isValid = one.and(two).test("HelloWorld");
        System.out.println("字符串符合要求吗：" + isValid);
    }

    static void orMethod(Predicate<String> one, Predicate<String> two) {
        boolean isValid = one.or(two).test("HelloWorld");
        System.out.println("字符串符合要求吗：" + isValid);
    }

    static void negateMethod(Predicate<String> predicate) {
        boolean veryLong = predicate.negate().test("HelloWorld");
        System.out.println("字符串很长吗：" + veryLong);
    }
}
